var app = new Vue({
    el: "#main-content",
    data:{
        oldManList: {},
        oldMan: {},
        oldManId: "",
        caseList: {},
        kinsfolkList:{}
    },
    mounted: function () {
        this.getOldManList();

    },
    methods: {
        getOldManList: function () {
            axios({
                method: 'get',
                url: "nurse/oldmanlist",
                headers: {'token': localStorage.token,"url":window.location.pathname},
                // headers:{'token': localStorage.token},
            }).then((ins) => {
                console.log(ins);
                let nhDto = ins.data;
                let oldManList = nhDto.data;
                console.log(oldManList);
                if (nhDto.code == 200) {
                    app.oldManList = oldManList;
                    app.oldMan = oldManList[0];
                    app.oldManId = oldManList[0].id;

                    gatcaList(oldManList[0].id);
                    getKinsfolk(oldManList[0].id);
                } else if (nhDto.code == 500) {
                    location.href = "/500.html";
                }
            })
        },
        setOldManId: function (oldManId) {
            app.oldManId = oldManId;
            gatcaList(oldManId);
            getKinsfolk(oldManId);
            getOldManData(oldManId)
        },
        caseAdd:function () {
            location.href = 'paramedics-illnessAdd.html?oldManId='+app.oldManId;
        }
    }
});

//家属列表
function getKinsfolk (oldManId){
    let data=new URLSearchParams();
    data.append("oldManId",oldManId);
    axios({
        method: 'post',
        url: "nurse/kinsfolklist",
        data:data,
        headers: {'token': localStorage.token,"url":window.location.pathname},
    }).then((ins) => {
        let nhDto = ins.data;
        let kinsfolkList = nhDto.data;
        if (nhDto.code == 200) {
            app.kinsfolkList = kinsfolkList;
        } else if (nhDto.code == 500) {
            location.href = "/500.html";
        }
    })
};

//老人病例列表
function gatcaList(oldManId) {
    let data=new URLSearchParams();
    data.append("oldManId",oldManId);
    axios({
        method: 'post',
        url: "nurse/caselist",
        data:data,
        headers: {'token': localStorage.token,"url":window.location.pathname},
    }).then((ins) => {
        console.log(ins);
        let nhDto = ins.data.nhDto;
        let caseList = nhDto.data;
        if (nhDto.code == 200) {
            app.caseList = caseList;
        } else if (nhDto.code == 500) {
            location.href = "/500.html";
        }
    })
}

//老人基本信息
function getOldManData(oldManId) {
    let data=new URLSearchParams();
    data.append("oldManId",oldManId);
    axios({
        method: 'post',
        url: "nurse/oldmandata",
        data:data,
        headers: {'token': localStorage.token,"url":window.location.pathname}
    }).then((ins) => {
        console.log(ins.data);
        let nhDto = ins.data;
        let oldMan = nhDto.data;
        if (nhDto.code == 200) {
            app.oldMan = oldMan;
        } else if (nhDto.code == 500) {
            location.href = "/500.html";
        }
    })
};